$(function(){
	$('#tt').datagrid({
		url:'/heartbeatApkConfig/getHeartbeatApkConfigListPage'
	});
	
});

function doAdd(){
	$('#addForm').form('clear');
	
	$('#versionId').attr("disabled", false);
	$('#heartfileId').attr("disabled", false);
	$('#versionId').validatebox({ 
		required:true 
	});
	
	$('#addWin').window('open');
}

function doEdit(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$('#idId').val(record.id);
	$('#versionId').val(record.version);
	$('#remarkId').val(record.remark);
	
	$('#versionId').validatebox({ 
		required:false 
	});
	
	$('#versionId').attr("disabled", true);
	$('#heartfileId').attr("disabled", true);
	$('#addWin').window('open');
}

function doDel(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	var heartbeatApkConfigId=record.id;
	$.ajax({
		url: '/heartbeatApkConfig/deleteHeartbeatApkConfig',
		type: 'POST',
		data : {
            id:heartbeatApkConfigId,
            delete_flag:1
		},
		success : function(data) {
			if (data.return_code == '1') {
				$.messager.alert(market.content.title, "删除成功");
				$("#tt").datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		error : function(e) {
			$.messager.alert("未知错误");
		}
	})
}

function doSearch(){
	
	var sversionId=$('#sversionId').val();
	$('#tt').datagrid({
		url:'/heartbeatApkConfig/getHeartbeatApkConfigListPage',
		queryParams:{
			version:sversionId
		}
	});
	$('#tt').datagrid('unselectAll');
}

function save(){
	var id=$('#idId').val();
	var url='/heartbeatApkConfig/updateHeartbeatApkConfig';
	if(id==null||id==''){
		url='/heartbeatApkConfig/saveHeartbeatApkConfig';
	}
	
	$('#addForm').form('submit',{
		url : url,
		onSubmit : function() {
			var flag = $(this).form('validate');
			if (!flag) {
				return flag;
			}
			showProcess(true, market.content.title, market.content.submitting);
			return true;
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$("#tt").datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
	
}

function cancel(){
	$('#addWin').window('close');
}

function typeFormatter(value){
	if(value==1){
		return '是';
	}else{
		return '否';
	}
}